package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionSortDemo03 {
    public static void main(String[] args) {

    Point p1 = new Point(10,20);
    Point p2 = new Point(5,30);
    List<Point> list = new ArrayList<>();
    list.add(p1);
    list.add(p2);

    Comparator<Point> comparator1 = new Comparator<Point>() {
        @Override
        public int compare(Point o1, Point o2) {
            return o1.getX()-o2.getX();
        }
    };

    Comparator<Point> comparator2 = new Comparator<Point>() {
        @Override
        public int compare(Point o1, Point o2) {
            return o1.getY()-o2.getY();
        }
    };

        Collections.sort(list,comparator1);
        System.out.println(list);
        Collections.sort(list,comparator2);
        System.out.println(list);



    }
}
